#pragma once
//封装实现锁
#include<iostream>
#include<pthread.h>
#include<mutex>

class Mutex
{
public:
    Mutex()
    {
        //调用mutex 的初始化函数
        pthread_mutex_init(&_lock , nullptr);
    }
    void Lock()
    {
        pthread_mutex_lock(&_lock);
    }
    void Unlock()
    {
        pthread_mutex_unlock(&_lock);
    }
    ~Mutex()
    {
        pthread_mutex_destroy(&_lock);
    }
private:
    pthread_mutex_t _lock;
};

class LockGuard
{
public:
    LockGuard(Mutex* _mutex):_mutexp(_mutex)
    {
        _mutexp->Lock();
    }
    ~LockGuard()
    {
        _mutexp->Unlock();
    }
private:
    Mutex* _mutexp;
};
